package com.estar.assistsurvy.adapter;

import java.util.List;

import com.estar.assistsurvy.R;
import com.estar.assistsurvy.entity.Evaluation;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

public class EvaluateListAdapter extends BaseAdapter {

	private List<Evaluation> evaluates;
	private LayoutInflater inflater;
	public EvaluateListAdapter(List<Evaluation> evaluates, Context context) {
		super();
		this.evaluates = evaluates;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return evaluates.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return evaluates.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView==null){
			convertView=inflater.inflate(R.layout.listview_taskdetail, null);
			holder=new ViewHolder();
			holder.task_icon=(ImageView) convertView.findViewById(R.id.task_icon);
			holder.task_name=(TextView) convertView.findViewById(R.id.task_name);
			holder.star_container=(RatingBar) convertView.findViewById(R.id.star_container);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		Evaluation evaluate=evaluates.get(position);
		holder.task_icon.setImageResource(R.drawable.icon_detail06);
		holder.task_name.setText(evaluate.getEvaluateName());
		//滑块的星形数量
		holder.star_container.setNumStars(5);
        //设置最大值
        holder.star_container.setMax(5);
        //设置每次更改的最小长度
        holder.star_container.setStepSize((float) 1);
        //设置分数
		holder.star_container.setRating(evaluate.getEvaluateScore());
		return convertView;
	}
	
	private class ViewHolder{
		private ImageView task_icon;
		private TextView task_name;
		private RatingBar star_container;
	}

}
